package org.cocos2dx.sdk;

import java.lang.reflect.Method;

public class JSdk {
	public String call(String func,int argv) {
		Method[] methods = this.getClass().getMethods();
		for (Method method : methods) {
			 if(method.getName().equals(func)){
				 Class<?>[] classes = method.getParameterTypes();
				 Object[] args = new Object[classes.length];
				 for (int i = 0;i < args.length;i++) {
					if (classes[i] == boolean.class || classes[i] == Boolean.class) {
						args[i] = getBoolArg(argv);
					}else if (classes[i] == char.class || classes[i] == Character.class) {
						args[i] = getCharArg(argv);
					}else if (classes[i] == int.class || classes[i] == Integer.class) {
						args[i] = getIntArg(argv);
					}else if (classes[i] == long.class || classes[i] == Long.class) {
						args[i] = getLongArg(argv);
					}else if (classes[i] == float.class || classes[i] == Float.class) {
						args[i] = getFloatArg(argv);
					}else if (classes[i] == double.class || classes[i] == Double.class) {
						args[i] = getDoubleArg(argv);
					}else if (classes[i] == String.class) {
						args[i] = getStringArg(argv);
					}else{
						return "Call Fial!";
					}
				}
				try {
					Object result = method.invoke(this, args);
					return result!=null?result.toString():null;
				} catch (Exception e) {
					e.printStackTrace();
				}
			 }
		}
		return "Call Fial!";
	}

	public native void postNotification(String notify,String value);
	public native boolean getBoolArg(int argv);
	public native char getCharArg(int argv);
	public native int getIntArg(int argv);
	public native long getLongArg(int argv);
	public native float getFloatArg(int argv);
	public native double getDoubleArg(int argv);
	public native String getStringArg(int argv);
}
